package com.audaque.springboot.foshanupload.web.mbmuldemo.mpgt.action;

import cn.hutool.core.bean.BeanUtil;
import com.audaque.springboot.foshanupload.core.model.qo.BaseQo;
import com.audaque.springboot.foshanupload.core.model.qo.IdQo;
import com.audaque.springboot.foshanupload.core.model.qo.page.Page;
import com.audaque.springboot.foshanupload.web.mbmuldemo.mpgt.api.SysUserMpgtApi;
import com.audaque.springboot.foshanupload.web.mbmuldemo.mpgt.dao.SysUserMpgtDao;
import com.audaque.springboot.foshanupload.web.mbmuldemo.mpgt.model.pojo.SysUserMpgtPojo;
import com.audaque.springboot.foshanupload.web.mbmuldemo.mpgt.model.qo.SysUserMpgtQo;
import com.audaque.springboot.foshanupload.web.mbmuldemo.mpgt.model.req.SysUserMpgtReq;
import com.audaque.springboot.foshanupload.web.mbmuldemo.mpgt.service.SysUserMpgtService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;

import java.util.List;


/**
 * @Description:用户信息表 管理
 * @Auther:zhong.guobin
 * @DateTime:2023-01-23T02:16:18.507
 */
@Controller
public class SysUserMpgtAction implements SysUserMpgtApi {
    @Autowired
    private SysUserMpgtService sysUserMpgtService;


    @Autowired
    private SysUserMpgtDao sysUserMpgtDao;



    public String insert(@RequestBody SysUserMpgtPojo pojo) throws Exception{
        return sysUserMpgtDao.insert(pojo, false);
    }


    public void update(@RequestBody SysUserMpgtPojo pojo) throws Exception {
            sysUserMpgtDao.update(pojo);
    }


    public void delete(@RequestBody BaseQo baseQo)  throws Exception{
        IdQo idQo = baseQo.getIdQo();
        String id =null;
        if(idQo!=null){
            id = idQo.getId();
        }
            sysUserMpgtDao.delete(id);
    }



    public Page<SysUserMpgtPojo> queryAndCount(@RequestBody SysUserMpgtReq req) throws Exception {
        req.initPage();
            SysUserMpgtQo qo = BeanUtil.toBean(req, SysUserMpgtQo.class);
        Integer offset = req.getOffset();
        Integer limit = req.getLimit();
        qo.setLimitQo(offset,limit);
        Page<SysUserMpgtPojo> page = sysUserMpgtDao.queryAndCount(null, qo);
        return page;
    }


    public  Page<SysUserMpgtPojo> queryThenCount(@RequestBody SysUserMpgtReq req)throws Exception {
        req.initPage();
            SysUserMpgtQo qo = BeanUtil.toBean(req, SysUserMpgtQo.class);
        Integer offset = req.getOffset();
        Integer limit = req.getLimit();
        qo.setLimitQo(offset, limit);
        Page<SysUserMpgtPojo> page = sysUserMpgtDao.queryThenCount(null, qo);
        return page;
    }

    public  Page<SysUserMpgtPojo> queryThenCountHelper(@RequestBody SysUserMpgtReq req)throws Exception {
        req.initPage();
            SysUserMpgtQo qo = BeanUtil.toBean(req, SysUserMpgtQo.class);
        Integer offset = req.getOffset();
        Integer limit = req.getLimit();
        qo.setLimitQo(offset, limit);
        Page<SysUserMpgtPojo> page = sysUserMpgtDao.queryThenCountHelper(null, qo);
        return page;
    }

   public  Page<SysUserMpgtPojo> queryThenCountHelper2(@RequestBody SysUserMpgtReq req)throws Exception {
        req.initPage();
            SysUserMpgtQo qo = BeanUtil.toBean(req, SysUserMpgtQo.class);
        Integer offset = req.getOffset();
        Integer limit = req.getLimit();
        qo.setLimitQo(offset, limit);
        Page<SysUserMpgtPojo> page = sysUserMpgtDao.queryThenCountHelper2(null, qo);
        return page;
    }
   public  Page<SysUserMpgtPojo> queryThenCountHelper3(@RequestBody SysUserMpgtReq req)throws Exception {
        req.initPage();
            SysUserMpgtQo qo = BeanUtil.toBean(req, SysUserMpgtQo.class);
        Integer offset = req.getOffset();
        Integer limit = req.getLimit();
        qo.setLimitQo(offset, limit);
        Page<SysUserMpgtPojo> page = sysUserMpgtDao.queryThenCountHelper3(null, qo);
        return page;
    }



    public List<SysUserMpgtPojo> findList(@RequestBody SysUserMpgtReq req) {
            SysUserMpgtQo qo = BeanUtil.toBean(req, SysUserMpgtQo.class);
        List<SysUserMpgtPojo> list = sysUserMpgtDao.queryList(null, qo);
        return list;
    }


    public SysUserMpgtPojo queryItem(@RequestBody SysUserMpgtReq req) {
            SysUserMpgtQo qo = BeanUtil.toBean(req, SysUserMpgtQo.class);
            SysUserMpgtPojo model = sysUserMpgtDao.queryItem(null, qo);
        return model;
    }



    public SysUserMpgtPojo queryItemByPrimaryKey(@RequestBody BaseQo baseQo)  throws Exception{
        IdQo idQo = baseQo.getIdQo();
        String id =null;
        if(idQo!=null){
            id = idQo.getId();
        }
            SysUserMpgtPojo model = sysUserMpgtDao.queryItem(id);
        return model;
    }



    public Integer count(@RequestBody SysUserMpgtReq req) {
            SysUserMpgtQo qo = BeanUtil.toBean(req, SysUserMpgtQo.class);
        Integer count = sysUserMpgtDao.count(qo);
        return count;
    }


}
